package com.goldsprite.microhorigame.screens.examples.ruletilemap;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.Array;

public class TextureRegionCutter {

	public static Array<TextureRegion> cutTexture(Texture texture, int unitSize, int rows, int cols) {
		if (texture == null) {
			return new Array<>();
		}

		int textureWidth = texture.getWidth();
		int textureHeight = texture.getHeight();

		// 验证纹理尺寸
		if (textureWidth % unitSize != 0 || textureHeight % unitSize != 0) {
			throw new IllegalArgumentException("纹理尺寸必须是unitSize的整数倍");
		}

		Array<TextureRegion> regions = new Array<>();

		for (int row = 0; row < rows; row++) {
			for (int col = 0; col < cols; col++) {
				int x = col * unitSize;
				int y = row * unitSize;
				TextureRegion region = new TextureRegion(texture, x, y, unitSize, unitSize);
				regions.add(region);
			}
		}

		return regions;
	}
}
